package org.arch_learn.io.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * 消息解码器
 */
public class MessageDecoder extends MessageToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, Object msg, List list) throws Exception {
        System.out.println("收到消息，并开始进行消息解码...");
        ByteBuf byteBuf = (ByteBuf) msg;
        list.add(byteBuf.toString(CharsetUtil.UTF_8));
    }
}
